<?php
require './include/global.php';
require './include/validate.php';
require './include/all_left.php';

require_once './include/advisory_db.php';
$status = $_SESSION['status'];
$isTr = 'Trial' != $status && 'Standard' != $status;
$smarty->assign('isTr',$isTr);
//print_r($_SESSION);
$smarty->compile_check = true;

$smarty->display('header.tpl');


if($_GET[action]=='delete'){
     $rs = $DB->fetch_one_array("SELECT * FROM " . $db_prefix . "resume WHERE `re_id`='".$_GET[id]."' AND `re_uid`= '".$_SESSION[uid]."'");
     if(empty($rs)){
	  echo "DATABASE ERROR";
	  exit;
	 }
     $sql = "DELETE FROM " . $db_prefix . "resume WHERE `re_id`=".$_GET[id];
     $DB->query($sql);
}


if($_GET[country]==''){
$_GET[country] = 211;
}
$smarty->assign('s',$_GET);
//jobupdate
$smarty->assign('jobupdate_names',$UPDATE);
$smarty->assign('state',$state);
$smarty->assign('country',$country);
$smarty->assign('industry',$jobcategory);
$smarty->assign('jobtype',$jobtype);
$smarty->assign('rec_myresume',$rec_myresume);


$where = "  WHERE `re_usertype`='".$_SESSION[usertype]."' AND `re_uid`='".$_SESSION[uid]."' ";
if($_GET[action]!='search' && $_GET[fid]=='') $where .= " AND re_aliasid = '0'  ";
if($_GET[fid]!='') $where .= " AND re_fid = '".$_GET[fid]."' ";

$order = " ORDER BY re_regtime DESC";
if($_GET[action]=="search"){ 

	if($_GET[orderby]=='0'){$by = "re_id";}
	else{
		$ord   = array('','re_fname','re_jobindustry','re_jobtitle','re_lostate','re_regtime','re_jobsearchstatus');
		$by = $ord[$_GET[orderby]];
		$get[] = "orderby=$_GET[orderby]";
	}
	if($_GET[name]!='')      {$arr[] = " (`re_fname` like '%".$_GET[name]."%' OR `re_lname` like '%".$_GET[name]."%') ";}
	if($_GET[keywords]!='')  { $arr[] = " (`re_jobtitle`  like '%".$_GET[keywords]."%' OR  `re_fname` like '%".$_GET[keywords]."%' OR `re_lname` like '%".$_GET[keywords]."%' OR `re_detail` like '%".$_GET[keywords]."%') ";}	
	if($_GET[industry]!='0'&&$_GET[industry]!='') { $arr[] = " `re_jobindustry` = '".$_GET[industry]."'  ";}
	if($_GET[jobtitle]!='')  { $arr[] = " `re_jobtitle`  like '%".$_GET[jobtitle]."%'  ";}	
	if($_GET[jobtype]!='0')  { $arr[] = " `re_jobtype` like '%".$_GET[jobtype]."%'  ";}
    if($_GET[jobupdate]!='') { $arr[] = " (UNIX_TIMESTAMP( ) - `re_updtime`) < (3600*24*".$_GET[jobupdate].")" ;}
	if($_GET[alias]!=1)      { $arr[] = "  re_aliasid = '0'  "; }if($_GET[orderby]=='0'){ $by = " re_fname ";}


	//print_r($arr);
	if(!empty($arr)){
		$implode  = @implode("AND", $arr);
		$implode  = " AND ".$implode;
		$where    .= $implode;
	}
    $order = " GROUP BY re_id, re_fname ORDER BY $by ASC";
}

if($_GET[tp]==1){
	$by    = "re_id"; 
	$order = "DESC" ;

	$_GET[order1]==''&&$order1=1;$_GET[order2]==''&&$order2=1;$_GET[order3]==''&&$order3=1;$_GET[order4]==''&&$order4=1;
	$_GET[order5]==''&&$order5=1;$_GET[order6]==''&&$order6=1;$_GET[order7]==''&&$order7=1;
	switch($_GET[swh]){
	   case 1:
		   $by = "re_fname";
		   if($_GET[order1]==1){$order_arr[1]=2; $order=" DESC ";$image_arr[1] = "<img src=\"images/dot1.gif\" align=\"absmiddle\">";}else{$order_arr[1]=1;$order=" ASC ";$image_arr[1] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	   case 2:
		   $by = "re_jobindustry";
		   if($_GET[order2]==1){$order_arr[2]=2; $order=" DESC ";$image_arr[2] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[2]=1;$order=" ASC ";$image_arr[2] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	   case 3:
			$by = "re_jobtitle";
		   if($_GET[order3]==1){$order_arr[3]=2; $order=" DESC ";$image_arr[3] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[3]=1;$order=" ASC ";$image_arr[3] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	   case 4:
		   $by = "re_lostate";
		   if($_GET[order4]==1){$order_arr[4]=2; $order=" DESC ";$image_arr[4] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[4]=1;$order=" ASC ";$image_arr[4] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
		case 5:
		   $by = "re_regtime";
		   if($_GET[order5]==1){$order_arr[5]=2; $order=" DESC ";$image_arr[5] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[5]=1;$order=" ASC ";$image_arr[5] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	   case 6:
		   $by = "re_jobsearchstatus";
		   if($_GET[order6]==1){$order_arr[6]=2; $order=" DESC ";$image_arr[6] = "<img src=\"images/dot1.gif\"  align=\"absmiddle\">";}else{$order_arr[6]=1;$order=" ASC ";$image_arr[6] = "<img src=\"images/dot2.gif\"  align=\"absmiddle\">";}
		   break;
	}
		$smarty->assign("order_arr",$order_arr);
		$smarty->assign("image_arr",$image_arr);
     $order = " ORDER BY $by $order ";

}



$nav = new buildNav;
$nav->limit = 25;
$total = $DB->fetch_one_array("SELECT COUNT(*) AS count FROM pa_resume $where");
$nav->total_result = $total[count];

$nav->execute("SELECT * FROM pa_resume $where $order");

$page = $nav->pagenav();
//echo $sql2;

$i=0;
while($list2 = $DB->fetch_array($nav->sql_result)){
   $datajob[$i]              = $list2;
   $datajob[$i][fid]         = $list2[re_fid];
   $datajob[$i][invite]      = getStatusOfinvite("",$_SESSION[uid],$list2[re_id]);
   $datajob[$i][name]        = $list2[re_fname]." ".$list2[re_lname] ;
   $datajob[$i][industry]    = ($list2[re_jobindustry] == 0)?"N/A":$jobcategory[$list2[re_jobindustry]];
   $datajob[$i][location]    = (($list2[re_lostate]==0)?"N/A":$state[$list2[re_lostate]]).",".(($list2[re_locountry]==0)?"N/A":$country[$list2[re_locountry]]);
   $datajob[$i][re_type]     = $jobtype[$list2[re_type]];
   $datajob[$i][re_jobsearchstatus] = ($list2[re_jobsearchstatus]!=0)?$jobSearchStatus[$list2[re_jobsearchstatus]]:"N/A";
   $datajob[$i][re_regtime]  = @date("m/d/Y",$list2[re_regtime]);
    $aliasnum               = $DB->fetch_one_array("SELECT re_id FROM pa_resume WHERE re_fid = '".$datajob[$i][re_id]."'");
     if(!empty($aliasnum)){
      $datajob[$i][alias]    = 1;
   }
   $i++;
}

$_SESSION[backurl2] = "mycandidates.php?fid=$_GET[fid]";

$mycandidates = ($_GET[fid])?" My Candidates - ".$datajob[0][name]." Alias list ":" My Candidates ";
$smarty->assign("copname" , $mycandidates);

$smarty->assign("resumelist",$datajob);
$smarty->assign("page",$page);
if($err!=''){
$smarty->assign("err",$err);
}
$smarty->assign("search",$reg_data);
$smarty->display('allleft.tpl');
$smarty->display('mycandidate.tpl');
$smarty->display('footer.tpl');


?>